/**
*
*/
import gameUtils.Coordinate;

import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.SwingUtilities;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.ImageIcon;

public class MainMenu extends JFrame implements MouseListener{
        
        public static final long serialVersionUID = 1;
        // Since there is only one of this being made... we can reference this inst.
       // public MainMenu INSTANCE = this;
        //Coordinate
   //     public Coordinate click;
        // Thread to move game along
        public Thread goToCutScenes;
        // Our handy dandy Hotspot ::DING::
     //   public MainMenuHotspot MainMenuListener;
        //The Cutscenes.. Of Course...
        public CutScenes cutScenes;
        public BufferedImage hotspot; 
        
        public MainMenu(){
//                System.out.println("start");
//                
            addMouseListener(this);
        	JLabel a = new JLabel(new ImageIcon("src/menu2.jpg"));  
        	a.setBounds(0,0,640,597);
        	add(a);

        	this.hotspot=setHotspot();
                System.out.println("hotspot class instantialized");
                
                final Runnable startGame = new Runnable(){
                        public void run(){
                                setVisible(false);
                                dispose();
                                cutScenes = new CutScenes(new JFrame());
                                cutScenes.startCS();        
                        }
                };
                this.goToCutScenes= new Thread(startGame, "Start Game");
        }
        
        public static void main(String args[]){
                SwingUtilities.invokeLater(new Runnable(){
                        public void run(){
                                createAndShowGUI();
                        }
                });
        }
        private static void createAndShowGUI(){
                MainMenu frame = new MainMenu();
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.setSize(640, 597);
                frame.setLocationRelativeTo( null );
                frame.setTitle("DaveHeim - Main Menu - ");
                frame.setVisible(true);
        }
        public BufferedImage setHotspot(){ 
        	try{ 
                   hotspot = ImageIO.read(new File("src/menuHotspot.jpg")); 
                    System.out.println("Hotspot Loaded"); 
                    return hotspot; 
            }
        	catch(IOException $e){} 
            return null; 
            
        }         
        public void mouseExited(MouseEvent e){}
        public void mouseEntered(MouseEvent e){}
        public void mousePressed(MouseEvent e){}
        public void mouseReleased(MouseEvent e){}
        public void mouseClicked(MouseEvent e){
        	int color = hotspot.getRGB(e.getX(), e.getY()); 
        	System.out.println(color);
            //System.out.println(Integer.toHexString(color)); 
            if(color == 0xFFFFFF){ 
                    System.out.println("Missed"); 
                   // mainMenu.click = null; 
            }else if(color == -16711423){ 
                    System.out.println("Start"); 
                    goToCutScenes.start(); 
            }else if(color == -6974059){ 
                    System.out.println("Exit"); 
                    System.exit(0); 
            }else{ 
                    System.err.println("We have a problem"); 
            }         
        }
        
        
        
}
